<?php 
#page title
$this->pageTitle=Yii::app()->name . ' - '.Yii::t("UserModule.user", "Profile");
#breadcrumbs
$this->breadcrumbs=array(
	Yii::t("UserModule.user", "Profile")=>array('profile'),
	Yii::t("UserModule.user", "Edit"));
#title
$this->title = Yii::t("UserModule.user", 'Edit profile');
#menu
$this->menu = array(
	YumMenuItemHelper::manageUsers(),
	YumMenuItemHelper::listUsers(),
	//YumMenuItemHelper::manageRoles(),
	YumMenuItemHelper::backToProfile(),
	YumMenuItemHelper::changePassword(),
	YumMenuItemHelper::logout());
?>

<?php if(Yii::app()->user->hasFlash('profileMessage')): ?>
<div class="success">
<?php echo Yii::app()->user->getFlash('profileMessage'); ?>
</div>
<?php endif; ?>
<div class="form">

<?php echo CHtml::beginForm(); ?>

<?php echo YumHelper::requiredFieldNote(); ?>

<?php echo CHtml::errorSummary($model);
  echo CHtml::errorSummary($profile); ?>
<?php 
$profileFields=YumProfileField::model()->forOwner()->sort()->with('group')->together()->findAll();

if ($profileFields) 
{
	foreach($profileFields as $field) 
	{
			?>
	<div class="row">
	<?php  echo CHtml::activeLabelEx($profile,$field->varname);
			if ($field->range) 
			{
				echo CHtml::activeDropDownList($profile,
						$field->varname,
						YumProfile::range(Yii::t("UserModule.user",$field->range)),array('style'=>'width:235px',));
			}else{ 
			if ($field->field_type=="TEXT") {
				echo CHtml::activeTextArea($profile,
						$field->varname,
						array('style'=>'width:230px; height: 100px',));
			}else{
				if ($field->field_type=="DATE") {
					$this->widget('zii.widgets.jui.CJuiDatePicker',
					array(
					'name'=>$field->varname,
					'value' => date(UserModule::$dateFormat, $profile->birthday),
					//  optional: jquery Datepicker options
					'options' => array(
						// how to change the input format? see http://docs.jquery.com/UI/Datepicker/formatDate
						'dateFormat'=>'mm-dd-yy',
			
						// user will be able to change month and year
						'changeMonth' => 'true',
						'changeYear' => 'true',
						// shows the button panel under the calendar (buttons like "today" and "done")
						'showButtonPanel' => 'false',
						// this is useful to allow only valid chars in the input field, according to dateFormat
						'constrainInput' => 'true',
						// speed at which the datepicker appears, time in ms or "slow", "normal" or "fast"
						'duration'=>'fast',
					),
							// optional: html options will affect the input element, not the datepicker widget itself
					'htmlOptions'=>array(
					'style'=>'width:235px;'
					)
		
			 // tells the widget to show the calendar inline
					)
					);
				}else{
					if ($field->editable==1){
					echo CHtml::activeTextField($profile,
						$field->varname,
						array('size'=>35,'maxlength'=>(($field->field_size)?$field->field_size:255)));
					}else{
					echo CHtml::activeTextField($profile,
						$field->varname,
						array('disabled'=>'disabled','size'=>35,'maxlength'=>(($field->field_size)?$field->field_size:255)));
					}
				}
				}
			}
			echo CHtml::error($profile,$field->varname); ?>
	</div>	
			<?php
			}
		}
?>
	<div class="row" style='display: none;'>
		<?php echo CHtml::activeLabelEx($model,'username'); ?>
		<?php echo CHtml::activeTextField($model,'username',array('size'=>35,'maxlength'=>255)); ?>
		<?php echo CHtml::error($model,'username'); ?>
	</div>

	<div class="row" style='display: none;'>
		<?php 
		echo CHtml::activeLabelEx($profile, 'privacy'); 
		echo CHtml::activeDropDownList($profile, 'privacy',
				array(
					'protected' => Yii::t('UserModule.user', 'protected'),
					'private' => Yii::t('UserModule.user', 'private'),
					'public' => Yii::t('UserModule.user', 'public'),
					)); 
				echo CHtml::error($profile,'privacy'); 
	?>
		</div>
	<div class="row action">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t("UserModule.user", 'Create') : Yii::t("UserModule.user", 'Save')); ?>
	</div>

<?php echo CHtml::endForm(); ?>

</div><!-- form -->
